# (MSYS2) Maintainer: Ray Donnelly <mingw.android@gmail.com>
# (ArchLinux) Maintainer: Christian Hesse <mail@eworm.de>
# (ArchLinux) Contributor: Alexey Vasiliev <robbinton@gmail.com>

_realname=freerdp
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
pkgdesc="Free RDP client (mingw-w64)"
_base_ver=2.0.0
_rc_ver=-rc4
pkgver=${_base_ver}${_rc_ver//-/}
pkgrel=1
depends=("${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
arch=('any')
url="https://www.freerdp.com/"
license=('Apache License 2.0')
provides=("${MINGW_PACKAGE_PREFIX}-freerdp")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/FreeRDP/FreeRDP/archive/${_base_ver}${_rc_ver}.tar.gz"
        msys-makefiles-generator.patch
        mingw-w64-redefinitions.patch)
sha256sums=('3406f3bfab63f81c1533029a5bf73949ff60f22f6e155c5a08005b8b8afe6d49'
            'de6d5017115c952db813eb878a62e66f2a617b380f1ff2036b27c85b2c1e811c'
            'e439ca5d91a93b61c31328f8b4ffa7c8e140421e11360db421c9d60f0ca483ce')

prepare() {
  cd "${srcdir}"/${_realname}-${_base_ver}${_rc_ver}
  patch -p1 -i ${srcdir}/msys-makefiles-generator.patch
  patch -p1 -i ${srcdir}/mingw-w64-redefinitions.patch
}

build() {
  [[ -d ${CARCH}-build ]] && rm -rf ${CARCH}-build
  mkdir ${CARCH}-build && cd ${CARCH}-build
  MSYS2_ARG_CONV_EXCL=-DCMAKE_INSTALL_PREFIX \
  ${MINGW_PREFIX}/bin/cmake \
      -G"MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_WINDOWS_VERSION="WIN7" \
      -DWITH_PULSE=OFF \
      -DWITH_SERVER=ON \
      -DMSVC_RUNTIME="dynamic" \
      ../${_realname}-${_base_ver}${_rc_ver}

  make VERBOSE=1
}

package() {
  cd ${CARCH}-build
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${_base_ver}${_rc_ver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
